package com.example.spring_data_jpa4.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "cst_customer")
public class Customer {
	@Id//声明当前私有属性为主键
    @GeneratedValue(strategy=GenerationType.IDENTITY) //配置主键的生成策略
    @Column(name="cust_id")
    private Long custId;
    
    @Column(name="cust_name") 
    private String custName;
    
    @Column(name="cust_source")
    private String custSource;
    
    @Column(name="cust_industry")
    private String custIndustry;
    
    @Column(name="cust_level")
    private String custLevel;
    
    @Column(name="cust_address")
    private String custAddress;
    
    @Column(name="cust_phone")
    private String custPhone;
    
    //配置客户和联系人之间的关系(一对多关系)
    /*
     * 使用注解的形式配置多表关系
     *    1.声明关系 @OneToMany
     *       targetEntity=对方对象的字节码对象
     *    2.配置外键 @JoinColumn
     *      name:从表外键字段名称
     *      referencedColumnName：参照的主表的主键字段名称
     */
//    @OneToMany(targetEntity = LinkMan.class)
//    @JoinColumn(name = "lkm_cust_id",referencedColumnName = "cust_id")
    /*
     *  放弃外键的维护权，mappedBy=对方的外键属性名,cascade：配置级联
     */
    @OneToMany(mappedBy = "customer",cascade = CascadeType.ALL)
    private Set<LinkMan> linkMans=new HashSet<LinkMan>();

    
	public Customer() {
		super();
	}

	public Customer(Long custId, String custName, String custSource, String custIndustry, String custLevel,
			String custAddress, String custPhone) {
		super();
		this.custId = custId;
		this.custName = custName;
		this.custSource = custSource;
		this.custIndustry = custIndustry;
		this.custLevel = custLevel;
		this.custAddress = custAddress;
		this.custPhone = custPhone;
	}

	public Long getCustId() {
		return custId;
	}

	public void setCustId(Long custId) {
		this.custId = custId;
	}

	public String getCustName() {
		return custName;
	}

	public void setCustName(String custName) {
		this.custName = custName;
	}

	public String getCustSource() {
		return custSource;
	}

	public void setCustSource(String custSource) {
		this.custSource = custSource;
	}

	public String getCustIndustry() {
		return custIndustry;
	}

	public void setCustIndustry(String custIndustry) {
		this.custIndustry = custIndustry;
	}

	public String getCustLevel() {
		return custLevel;
	}

	public void setCustLevel(String custLevel) {
		this.custLevel = custLevel;
	}

	public String getCustAddress() {
		return custAddress;
	}

	public void setCustAddress(String custAddress) {
		this.custAddress = custAddress;
	}

	public String getCustPhone() {
		return custPhone;
	}

	public void setCustPhone(String custPhone) {
		this.custPhone = custPhone;
	}
	
	

	public Set<LinkMan> getLinkMans() {
		return linkMans;
	}

	public void setLinkMans(Set<LinkMan> linkMans) {
		this.linkMans = linkMans;
	}

	@Override
	public String toString() {
		return "Customer [custId=" + custId + ", custName=" + custName + ", custSource=" + custSource
				+ ", custIndustry=" + custIndustry + ", custLevel=" + custLevel + ", custAddress=" + custAddress
				+ ", custPhone=" + custPhone + "]";
	}
    
    
}
